import fs from 'fs-extra';
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/index.ts', 'src/vite/index.ts'],
  format: ['esm'],
  sourcemap: false,
  minify: false,
  clean: true,
  bundle: true,
  splitting: true,
  platform: 'node',
  shims: true,
  esbuildOptions: (options) => {
    return {
      ...options,
      alias: {
        '@': '/src/',
      },
    };
  },
  plugins: [
    {
      name: 'copy-config-plugin',
      buildStart() {
        fs.copySync('./src/config', 'dist/config');
        fs.copyFileSync(
          './src/plugin/rollup-plugin-models/provider.tsx',
          'dist/provider.tsx',
        );
        fs.copyFileSync(
          './src/plugin/rollup-plugin-models/use-model.ts',
          'dist/use-model.ts',
        );
      },
    },
  ],
});
